﻿/**
 *    Copyright 2012 Yohan Courbe
 *
 *  Licensed under the Apache License, Version 2.0 (the "License") 
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *      
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

using System;
using SharpGL;
using System.Drawing;
using SharpGL.SceneGraph.Assets;

namespace NetworkAnalyzer.Engines.Graphics
{
    public static class GLTools
    {
        public static void DrawCircle(this OpenGL gl, PointF point, float radius)
        {
            gl.Begin(OpenGL.GL_LINE_LOOP);

            for (int i = 0; i < 360; i += 1)
            {
                gl.Vertex(point.X + Math.Sin(i * Math.PI / 180) * radius, point.Y + Math.Cos(i * Math.PI / 180) * radius);
            }

            gl.End();
        }

        public static void FillCircle(this OpenGL gl, float x, float y, float radius)
        {
            gl.Begin(OpenGL.GL_POLYGON);

            for (int i = 0; i < 360; i += 1)
            {
                gl.Vertex(x + Math.Sin(i * Math.PI / 180) * radius, y + Math.Cos(i * Math.PI / 180) * radius);
            }

            gl.End();
        }

        public static void DrawTexture(this OpenGL gl, Texture texture, float x, float y, float w, float h, float r, float g, float b, float a)
        {
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture.Bind(gl);
            gl.Color(r, g, b, a);
            gl.Begin(OpenGL.GL_QUADS);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(x, y);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(x + w, y);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(x + w, y + h);
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(x, y + h);
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);
        }
    }
}
